var $ = require('../../common/helper.js');
Page({
	data: {
		data: [],
		offset: 0,
		loadmore: ''
	},
	onLoad: function (options) {
		$.overload(false);
	},
	onShow: function () {
		wx.startPullDownRefresh();
	},
	onPullDownRefresh: function () {
		this.getData();
	},
	onReachBottom: function () {
		this.getData(true);
	},
	//获取数据开始
	getData: function (isReachBottom, callback) {
		wx.showNavigationBarLoading();
		var _this = this, data = this.data.data, offset = this.data.offset;
		if (!isReachBottom) {
			data = [];
			offset = 0;
		}
		$.get('api.php?app=message&act=index', { offset: offset }, function (json) {
			wx.stopPullDownRefresh();
			wx.hideNavigationBarLoading();
			if ($.isArray(json.data)) {
				data = data.concat(json.data);
				offset += json.data.length;
			}
			var loadmore = '';
			if (_this.data.offset == offset || data.length < 6) {
				loadmore = 'loadmore-nomore';
			}
			_this.setData({
				data: data,
				offset: offset,
				loadmore: loadmore
			});
			if ($.isFunction(callback)) callback();
		});
	}
})